/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao.erp;

import com.openbravo.data.loader.query.QBFParameter;
import e.odbo.data.dao.ViewDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.sqlbuilder.QBFBuilder;
import com.openbravo.data.loader.serialize.serializer.read.SerializerReadClass;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;
import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.bean.erp.viewbean.CustomerPayment;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class CustomerPaymentDAO extends ViewDAO<CustomerPayment>{

    public CustomerPaymentDAO(I_Session s) {
        super(s);
    }
    

    public CustomerPayment readValues(DataRead dr,CustomerPayment c) throws BasicException {
        if(c==null)
        	c=new CustomerPayment();
        c.setName(dr.getString(1));
        c.setOrderType(dr.getString(2));
        c.setPaymentType(dr.getString(3));
        c.setM_dTotal(dr.getDouble(4));
        return c;
    }

    @Override
    public Class getSuportClass() {
        return CustomerPayment.class;
    }

    public List<CustomerPayment> list(Object filter) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT  C.NAME, E.NAME,PA.PAYMENT,SUM(PA.TOTAL)  "
                + "FROM  PAYMENTS PA,ORDERS T "
                + "LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID ,ORDERTYPES E,CUSTOMERS C "
                + "WHERE  PA.RECEIPT=T.ID AND T.DEFINETYPEREF = E.ID AND T.CUSTOMER=C.ID AND T.PERSON = P.ID AND ?(QBF_FILTER) "
                + "GROUP BY C.NAME, E.NAME,PA.PAYMENT", new String[]{"T.ORDERID", "T.DEFINETYPEREF", "T.ORDERTYPE", "T.CURDATE", "T.CURDATE", "P.NAME", "C.NAME", "T.LOCATIONREF", "T.TOTALPRICE"}), new SerializerWriteBasic(new Datas[]{Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.INT, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.DOUBLE}), this).list(filter);
    }

    @Override
    public List<CustomerPayment> query(QBFParameter filter) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT  C.NAME, E.NAME,PA.PAYMENT,SUM(PA.TOTAL)  "
                        + "FROM  PAYMENTS PA,ORDERS T "
                        + "LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID ,ORDERTYPES E,CUSTOMERS C "
                        + "WHERE  PA.RECEIPT=T.ID AND T.DEFINETYPEREF = E.ID AND T.CUSTOMER=C.ID AND T.PERSON = P.ID AND ?(QBF_FILTER) "
                        + "GROUP BY C.NAME, E.NAME,PA.PAYMENT"),null, this).list(filter);

    }
}
